<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%admin_log}}".
 *
 * @property integer $id
 * @property integer $add_time
 * @property string $info
 * @property string $ip
 * @property string $admin_id
 */
class AdminLog extends AR
{
    const  SYSTEM_TYPE_PLATFORM=1;
    const  SYSTEM_TYPE_SUPPLIER=2;
    const  SYSTEM_TYPE_DELIVERY=3;


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%admin_log}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['add_time', 'admin_id','system_type','supplier_id'], 'integer'],
            [['admin_id'], 'required'],
            [['info'], 'string', 'max' => 250],
            //[['model'], 'string', 'max' => 20],
            [['ip'], 'string', 'max' => 20]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'add_time' => 'Add Time',
            'info' => 'Info',
            'ip' => 'Ip',
            'admin_id' => '管理员ID',
        ];
    }
    
    public function beforeValidate() {
        if(parent::beforeValidate()){
            $this->add_time=time();
            $this->ip=Yii::$app->request->userIP;
            $this->admin_id=Yii::$app->user->id;
            return true;
        }else{
            return false;
        }
    }
}
